﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Text.RegularExpressions;

namespace XUtility
{
    /// <summary>
    /// 数据库连接字符串
    /// </summary>
    public class DataBaseConnection
    {
        /// <summary>
        /// 数据库连接字符串
        /// </summary>
        public static String connectionString = GetConnectionString();

        #region 获取 数据库连接字符串
        /// <summary>
        /// 获取 数据库连接字符串
        /// </summary>
        /// <returns></returns>
        public static String GetConnectionString()
        {
            String str = String.Empty;
            if (System.Configuration.ConfigurationManager.ConnectionStrings != null && System.Configuration.ConfigurationManager.ConnectionStrings.Count > 0)
            {
                foreach (ConnectionStringSettings item in System.Configuration.ConfigurationManager.ConnectionStrings)
                {
                    if (Regex.IsMatch(item.Name, "OS", RegexOptions.IgnoreCase))
                    {
                        str = item.ConnectionString;
                        break;
                    }
                }
            }
            return str;
        }
        #endregion

        #region 设置 数据库连接字符串
        /// <summary>
        /// 设置 数据库连接字符串
        /// </summary>
        /// <param name="strConnection"></param>
        public static void SetConnectionString(String strConnection)
        {
            connectionString = strConnection;
        }
        #endregion
    }
}
